import { Component, OnInit, Output, ChangeDetectionStrategy, EventEmitter } from '@angular/core';

type AlertTheme = 'primary' | 'success' | 'danger' | 'warning';

export interface AlertOption {
  content: string;
  theme?: AlertTheme;
}

@Component({
  selector: 'app-alert',
  templateUrl: './alert.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})

export class AlertComponent implements OnInit {
  options: Required<AlertOption> = {
    content: 'default-tip',
    theme: 'primary'
  };
  @Output() readonly closeAlert = new EventEmitter<void>();
  constructor() { }
  get wrapCls(): string {
    return `alert alert-${this.options.theme} fixed-top`;
  }
  ngOnInit() {
  }
  setOptions(options: AlertOption) {
    this.options = { ...this.options, ...options };
  }
  closed(): void {
    this.closeAlert.emit();
  }
}
